local app = require 'app'
local game = app.game.running

local ingame = game.ui.activity()

function ingame:ctor()
    self.res = 'club.threecard.doudizhu/ui/ingame.b:ingame'

    local ready = game.require 'ui.ingame.ready'
    self.ready = ready.new()
    self.ready:hide()

    local seats = game.require 'ui.ingame.seats'
    self.seats = seats.new(self)

    local dealer = game.require 'ui.ingame.dealer'
    self.dealer = dealer.new(self)

    local clock = game.require 'ui.ingame.clock'
    self.clock = clock.new(self)
    self.clock:hide()

    local seen_card = game.require 'ui.ingame.seen_card'
    self.seen_card = seen_card.new()

    local bidder = game.require 'ui.ingame.bidder'
    self.bidder = bidder.new(self)
    self.bidder:hide()

    local handouter = game.require 'ui.ingame.handouter'
    self.handouter = handouter.new(self)
    self.handouter:hide()

    local shortcut = game.require 'ui.ingame.shortcut'
    self.shortcut = shortcut.new(self)

    local phase_shower = game.require 'ui.ingame.phase_shower'
    self.phase_shower = phase_shower.new(self)
    self.phase_shower:hide()

    local left_count = game.require 'ui.ingame.left_count'
    self.left_count = left_count.new(self)
    self.left_count:hide()

    local settlement = game.require 'ui.ingame.settlement'
    self.settlement = settlement.new(self)

    local resumer = game.require 'ui.ingame.resumer'
    self.resumer = resumer.new(self)
end

function ingame:on_injected(bind)
    bind('button.click', self.exit_btn, self.on_exit_game)
    bind("shortcut.escape", self.exit_btn.gameObject, self.on_exit_game);

    game.utility.button_style.highlight_scale(self.exit_btn)
end

function ingame:on_exit_game()
    game.audio.post("doudizhu:click");
    game.game_scene.leave();
end

function ingame:on_load()
    self:super('on_load')
    
    self.ready:load()
    self.ready:set_parent(self.ready_root, false)

    self.seats:load()
    self.seats:set_parent(self.seat_root, false)

    self.dealer:load()
    self.dealer:set_parent(self.dealer_root, false)

    self.seen_card:load()
    self.seen_card:set_parent(self.seen_card_root, false)

    self.bidder:load()
    self.bidder:set_parent(self.bidder_root, false)

    self.clock:load()
    self.clock:set_parent(self.clock_root, false)

    self.handouter:load()
    self.handouter:set_parent(self.handouter_root, false)

    self.shortcut:load()
    self.shortcut:set_parent(self.shortcut_root, false)

    self.phase_shower:load()
    self.phase_shower:set_parent(self.phase_shower_root, false)

    self.left_count:load()
    self.left_count:set_parent(self.left_count_root, false)

    self.settlement:set_parent(self.settlement_root, false)

    self.resumer:load()
    self.resumer:set_parent(self.resumer_root, false)

    game.store.ingame.throttle(false)
end

function ingame:clear_scene()
    self.dealer:clear_scene()
    self.seen_card:clear_scene()
    self.bidder:clear_scene()
    self.seats:clear_scene()
    self.ready:clear_scene()
    self.handouter:clear_scene()
    self.phase_shower:clear_scene()
end

return ingame